package itbour.onetouchshow.fragment.me;


import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.afollestad.materialdialogs.OneToucDialog;
import com.andview.adapter.ABaseRefreshAdapter;
import com.andview.adapter.BaseRecyclerHolder;
import com.andview.listener.OnItemClickListener;
import com.google.gson.Gson;
import com.lsjr.utils.NetUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;
import itbour.onetouchshow.App;
import itbour.onetouchshow.R;
import itbour.onetouchshow.activity.SettingActivity;
import itbour.onetouchshow.activity.challengezone.ChallengeZoneActivity;
import itbour.onetouchshow.activity.challengezone.customvideopreview.CustomVideoPreviewActivity;
import itbour.onetouchshow.activity.login.LoginActivity;
import itbour.onetouchshow.activity.main.MainActivity;
import itbour.onetouchshow.activity.myorder.MyCollectActivity;
import itbour.onetouchshow.activity.myworks.MyWorksV3_0Activity;
import itbour.onetouchshow.activity.preview.verticalpreview.verticalproduct.VerticalproductActivity;
import itbour.onetouchshow.activity.userinfo.FeedBackActivity;
import itbour.onetouchshow.activity.userinfo.UserinfoActivity;
import itbour.onetouchshow.activity.userinfo.VipDetailActivity;
import itbour.onetouchshow.activity.version1_4.V1_4_VideoPreviewActivity;
import itbour.onetouchshow.activity.version1_6.MakeActivityV1_6;
import itbour.onetouchshow.activity.web.CommWebActivity;
import itbour.onetouchshow.activity.web.MyOrderListActivity;
import itbour.onetouchshow.base.BaseApplication;
import itbour.onetouchshow.base.mvp.MVPBaseFragment;
import itbour.onetouchshow.bean.DocsBean;
import itbour.onetouchshow.bean.HomeDetailslBean;
import itbour.onetouchshow.bean.MineItemBean;
import itbour.onetouchshow.bean.UserDetailInfoBean;
import itbour.onetouchshow.bean.UserWork;
import itbour.onetouchshow.bean.V1_4DocPreviewBean;
import itbour.onetouchshow.bean.VipInfoBean;
import itbour.onetouchshow.bean.eventbus.UpdateUserAction;
import itbour.onetouchshow.bean.user.UserMakeTag;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.constants.DataCreater;
import itbour.onetouchshow.constants.IntentCode;
import itbour.onetouchshow.constants.platform.DataPlatform;
import itbour.onetouchshow.constants.platform.WorkPlatform;
import itbour.onetouchshow.observable.NetWorkObservable;
import itbour.onetouchshow.singlecase.InchingDataSingleCase;
import itbour.onetouchshow.utils.ImageLoader;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.SpUtils;
import itbour.onetouchshow.utils.T_;
import itbour.onetouchshow.utils.UIUtils;
import itbour.onetouchshow.utils.recycleviewmanager.FullyLinearLayoutManager;
import itbour.onetouchshow.utils.video.MakeProductContrl;
import itbour.onetouchshow.utils.video.StatusBarUtils;
import itbour.onetouchshow.widget.CircleImageView;
import itbour.onetouchshow.widget.PopWindowMessageCenter;
import itbour.onetouchshow.widget.RoundImageView;

import static itbour.onetouchshow.bean.eventbus.UpdateUserAction.TYPE_CREATEWORK;
import static itbour.onetouchshow.bean.eventbus.UpdateUserAction.UPDATA_USER_NAME;
import static itbour.onetouchshow.bean.eventbus.UpdateUserAction.UPDAT_USER_AV;
import static itbour.onetouchshow.bean.eventbus.UpdateUserAction.UPDAT_USER_SGIN;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MeFragment extends MVPBaseFragment<MeContract.View, MePresenter> implements MeContract.View, NetWorkObservable.NetWorkObserver {

    /**
     * 进度条的dialog
     */
    public OneToucDialog oneToucDialog;
    @BindView(R.id.id_rv_me)
    RecyclerView idRvMe;
    @BindView(R.id.id_rv_user_work)
    RecyclerView rvUserWork;
    @BindView(R.id.id_more_work)
    TextView moreWork;
    @BindView(R.id.id_ig_user_av)
    CircleImageView idIgUserAv;
    @BindView(R.id.id_user_name)
    TextView idUserName;
    @BindView(R.id.id_user_signa)
    TextView idUserSigna;
    @BindView(R.id.id_ig_more)
    ImageView idIgMore;
    @BindView(R.id.id_tv_no_data)
    TextView tvNoWork;
    @BindView(R.id.id_update_ry)
    RelativeLayout updatRy;
    @BindView(R.id.iv_vip_icon)
    ImageView ivVipIcon;
    Unbinder unbinder;
    /*我的作品数据*/
    List<DocsBean> docs = new ArrayList<>();
    /*用户信息数据*/
    UserDetailInfoBean userDetailInfoBean;
    DocsBean docsBean;
    @BindView(R.id.v_status_bar)
    View vStatusBar;
    @BindView(R.id.mecenter_me_product)
    TextView mecenterMeProduct;
    Unbinder unbinder1;
    private List<MineItemBean> itemData = new ArrayList<>();
    private PcenterWorkAdapter pcenterWorkAdapter;
    private PcenterAdapter adapter;
    private V1_4DocPreviewBean docPreviewBean;
    private boolean isfirst = true;

    //客服弹框
    private PopWindowMessageCenter messageCenter;
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {
        @RequiresApi(api = Build.VERSION_CODES.M)
        @Override
        public void onClick(View v) {
            messageCenter.dismiss();
            switch (v.getId()) {
                case R.id.pw_join_qq_group:
                    HomeDetailslBean detailslBean = new Gson().fromJson(SpUtils.getInstance().getString(AppConst.APPBASEINFO), HomeDetailslBean.class);
                    String key = null;
                    if (detailslBean != null && !TextUtils.isEmpty(detailslBean.getAppControl().getqGroupUrl())) {
                        key = detailslBean.getAppControl().getqGroupUrl();
                    }
                    if (key != null) {
                        joinQQGroup(key);
                    }
                    break;
                case R.id.pw_phone_kefu:
                    if (!TextUtils.isEmpty(InchingDataSingleCase.INSTANCE.getAppControl().getTel())) {
                        goToCellPhoneActivity(InchingDataSingleCase.INSTANCE.getAppControl().getTel());
                    } else {
                        goToCellPhoneActivity("");
                    }
                case R.id.pw_cancel:
                    messageCenter.dismiss();
                    break;
            }
        }


    };

    @Override
    public void loadSucceed(String result) {
        UserWork userWork = new Gson().fromJson(result, UserWork.class);
        docs = userWork.getList();
        if (docs == null || userWork.getList().size() == 0) {
            tvNoWork.setVisibility(View.VISIBLE);
            rvUserWork.setVisibility(View.GONE);
        } else {
            tvNoWork.setVisibility(View.GONE);
            rvUserWork.setVisibility(View.VISIBLE);
        }
        pcenterWorkAdapter.notifyDataSetChanged(docs);
    }

    @Override
    public void loadFaild(String error) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void dataEvent(UpdateUserAction updateUserAction) {
        int subType = updateUserAction.getSubType();
        switch (subType) {
            case UPDAT_USER_SGIN:
                idUserSigna.setText(updateUserAction.getContent());
                userDetailInfoBean.getUserInfo().setSign(updateUserAction.getContent());
                break;
            case UPDATA_USER_NAME:
                idUserName.setText(updateUserAction.getContent());
                userDetailInfoBean.getUserInfo().setNickName(updateUserAction.getContent());
                break;
            case UPDAT_USER_AV:
                ImageLoader.getInstance().showImage(getActivity(), updateUserAction.getContent(), idIgUserAv);
                userDetailInfoBean.getUserInfo().setAvatarUrl(updateUserAction.getContent());
                break;
            case TYPE_CREATEWORK:
                //T_.showToastReal("刷新作品");
                mPresenter.loadPersonalCenterInfo();
                mPresenter.loadUserDetailInfo();
                break;
            default:
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (App.isLogin()) {
            mPresenter.loadPersonalCenterInfo();
            mPresenter.loadUserDetailInfo();
        } else {
            MainActivity mainActivity = (MainActivity) getActivity();
            if (AppConst.CURRENT_PAGE != -1) {
                mainActivity.viewPager.setCurrentItem(AppConst.CURRENT_PAGE, false);
            } else {
                mainActivity.viewPager.setCurrentItem(0, false);
            }

        }

    }

    @Override
    protected void onVisible() {
        super.onVisible();
        // T_.showToastReal("显示刷新");
        // mPresenter.loadPersonalCenterInfo();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_me;
    }

    @Override
    protected void afterCreate(Bundle savedInstanceState) {
        initStatusBar();
        itemData = DataCreater.getDefaultMineData();
        BaseApplication.instance().registerNetWorkObserver(this);
        if (App.isLogin()) {
            mPresenter.loadPersonalCenterInfo();
            mPresenter.loadUserDetailInfo();
        }

    }

    private void initStatusBar() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) vStatusBar.getLayoutParams();
        params.height = StatusBarUtils.getStatusBarHeight(getActivity());
        vStatusBar.setLayoutParams(params);
        vStatusBar.setBackgroundColor(getResources().getColor(R.color.app_status_bar_color));
    }

    @Override
    protected void initView() {
        super.initView();
        idRvMe.setHasFixedSize(true);
        idRvMe.setLayoutManager(new FullyLinearLayoutManager(getContext()));
        HomeDetailslBean basicInfo = new Gson().fromJson(SpUtils.getInstance().getString(AppConst.APPBASEINFO), HomeDetailslBean.class);
        idRvMe.addItemDecoration(new RecyclerView.ItemDecoration() {
            private int mSpace = UIUtils.dip2px(10);

            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                int childCount = parent.getChildCount();
                int pos = parent.getChildAdapterPosition(view);
                outRect.left = 0;
                outRect.top = 0;
                outRect.bottom = 0;
                if (pos == 2) {
                    outRect.top = mSpace;
                    if (!(basicInfo != null && basicInfo.getAppControl().getHiddenMyActivity() == 0
                            && basicInfo != null && basicInfo.getAppControl().getHiddenMyReward() == 0)) {
                        outRect.bottom = mSpace;
                    }
                } else if (pos == 3) {
                    if (basicInfo != null && basicInfo.getAppControl().getHiddenMyActivity() == 0
                            && basicInfo != null && basicInfo.getAppControl().getHiddenMyReward() == 0) {
                        outRect.bottom = mSpace;
                    }
                } else if (pos == 4) {
                    if (basicInfo != null && basicInfo.getAppControl().getHiddenMyActivity() == 0
                            && basicInfo != null && basicInfo.getAppControl().getHiddenMyReward() == 0) {
                        outRect.bottom = mSpace;
                    }
                } else if (pos != (childCount - 1)) {
                    outRect.right = mSpace;
                } else {
                    outRect.right = 0;
                }
            }


        });

        adapter = new PcenterAdapter(getContext(), itemData, R.layout.item_me_frag);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseRecyclerHolder baseRecyclerHolder, int position, Object item) {
                // {"我的订单", "我的收藏", "联系客服", "去评分", "设置"};
                if (App.isLogin()) {
                    Bundle bundle = null;
                    Intent intent;
                    if (NetUtils.isConnected(UIUtils.getContext())) {
                        switch (itemData.get(position).getItemName()) {
                            case "我的大赛":
                                bundle = new Bundle();
                                bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB_CHALLENGE);
                                openActivity(CommWebActivity.class, bundle);
                                break;
                            case "我的奖励":
                                bundle = new Bundle();
                                bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB_PROFIT);
                                openActivity(CommWebActivity.class, bundle);
                                break;
                            case "我的订单":
                                if (NetUtils.isConnected(UIUtils.getContext())) {
                                    openActivity(MyOrderListActivity.class);
                                } else {
                                    T_.showCustomToast("请检查网络");
                                }
                                break;
                            case "我的秀米":
                                // startActivity(XiuMiDetailActivity.getLaunchIntent(getActivity(), userDetailInfoBean.getUserInfo().getUserId()));
                                // openActivity(MineXiuMiActivity.class);
                                bundle = new Bundle();
                                bundle.putString(AppConst.WEBTYPE, AppConst.COMWEB_XIUMI);
                                openActivity(CommWebActivity.class, bundle);
                                break;
                            case "尊享会员":
                                mPresenter.getVipPageInfo();
                                showProgressDialog();
                                break;
                            case "我的收藏":
                                openActivity(MyCollectActivity.class);
                                break;
                            case "意见反馈":
                                openActivity(FeedBackActivity.class);
                                break;
                            case "联系客服":
                                showCustomServiceWindow();
                                break;
                            case "设置":
                                openActivity(SettingActivity.class);
                                break;
                            case "去评分":
                                Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
                                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                                try {
                                    startActivity(goToMarket);
                                } catch (ActivityNotFoundException e) {
                                    Toast.makeText(getActivity(), "没有找到应用市场", Toast.LENGTH_SHORT).show();
                                }
                                break;
                        }
                    } else {
                        T_.showCustomToast("请检查网络");
                    }

                } else {
                    openActivity(LoginActivity.class);
                }

            }
        });
        idRvMe.setAdapter(adapter);
        rvUserWork.setHasFixedSize(true);
        rvUserWork.setLayoutManager(new GridLayoutManager(getContext(), 4));
        pcenterWorkAdapter = new PcenterWorkAdapter(getContext(), null, R.layout.item_user_work);
        pcenterWorkAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseRecyclerHolder baseRecyclerHolder, int position, Object item) {
                docsBean = docs.get(position);
                int opType = docsBean.getOpType();
                switch (opType) {
                    case DataPlatform.ORTYPE_VERTICAL:
                        Intent intent = new Intent(getActivity(), VerticalproductActivity.class);
                        intent.putExtra(AppConst.DOCID, docsBean.getId());
                        intent.putExtra(AppConst.OPTYPE, opType);
                        intent.putExtra(WorkPlatform.TYPE, IntentCode.getProductBundle(WorkPlatform.WOEK));
                        startActivity(intent);
                        break;
                    case DataPlatform.ORTYPE_VIDIO:

                        if (docsBean.getState() == 1 || docsBean.getState() == 3) {

                            MakeProductContrl.instance().setInitialize(new MakeProductContrl.MakeProductListener() {
                                @Override
                                public void makeSuccess(String result) {
                                    Bundle bundle = new Bundle();
                                    bundle.putString(AppConst.DOCID, docsBean.getId() + "");
                                    bundle.putString(WorkPlatform.TYPE, WorkPlatform.W0RK);
                                    openActivity(V1_4_VideoPreviewActivity.class, bundle);
                                }

                                @Override
                                public void makeFaile() {
                                    Bundle bundle = new Bundle();
                                    bundle.putString(AppConst.DOCID, docsBean.getId() + "");
                                    bundle.putString(WorkPlatform.TYPE, WorkPlatform.W0RK);
                                    openActivity(V1_4_VideoPreviewActivity.class, bundle);
                                }

                                @Override
                                public void makeiing(String result) {
                                    // mPresenter.getDocString(docsBean.getId() + "");
                                }

                                @Override
                                public void lookLater() {

                                }

                                @Override
                                public void isDraft(String result) {


                                }
                            }, getActivity(), MakeProductContrl.SignalTag.SHOW_HINT, UserMakeTag.MAKE)
                                    .newLoadDocPreview(docsBean.getId() + "");

                        } else {
                            mPresenter.getDocString(docsBean.getId() + "");
                        }

                        break;
                    case DataPlatform.ORTYPE_PPT:
                        break;
                    default:
                        break;
                    case DataPlatform.ORTYPE_PERSONAL_CREATE:
                        if (docsBean.getState() != 3) {
                            mPresenter.getCustomVideodoccontent(docsBean.getId() + "");
                        } else {
                            Intent launchIntent = CustomVideoPreviewActivity.getLaunchIntent(getContext(), docsBean.getId() + "", UserMakeTag.WORK.getTypeName());
                            startActivity(launchIntent);
                        }
                        //自由创建作品
                        break;
                }

            }
        });
        rvUserWork.setAdapter(pcenterWorkAdapter);

    }

    @Override
    public void loaduserDetailSuccess(String result) {
        //L_.e(result);
        isfirst = false;
        userDetailInfoBean = new Gson().fromJson(result, UserDetailInfoBean.class);
        if (userDetailInfoBean == null) {
            return;
        }
        L_.e("loaduserDetailSuccess" + result);
        idUserName.setText(userDetailInfoBean.getUserInfo().getNickName());
        idUserSigna.setText(userDetailInfoBean.getUserInfo().getSign());
        ImageLoader.getInstance().showImage(getActivity(), userDetailInfoBean.getUserInfo().getAvatarUrl(), idIgUserAv);
        setUiIsVip(userDetailInfoBean.getIsVip(), Integer.parseInt(userDetailInfoBean.getUserInfo().getWallet().getPointBalance() == null ? "-1" : userDetailInfoBean.getUserInfo().getWallet().getPointBalance()));

        App.setIntegral(Integer.parseInt(userDetailInfoBean.getUserInfo().getWallet().getPointBalance() == null ? "-1" : userDetailInfoBean.getUserInfo().getWallet().getPointBalance()));
        App.setUserDetailInfoBean(userDetailInfoBean);
    }

    @Override
    public void loaduserDetailFail(String result) {

    }

    @Override
    public void loadVipInfoSuccess(String str) {
        isfirst = false;
        dismissProgressDialog();
        // 当appHomeVipUrl有值时跳转到Web页面 否则使用本地页面
        VipInfoBean vipInfoBean = new Gson().fromJson(str, VipInfoBean.class);
        InchingDataSingleCase.INSTANCE.setVipInfoBean(vipInfoBean);
        if (vipInfoBean != null && !TextUtils.isEmpty(vipInfoBean.getAppHomeVipUrl())) {
            Bundle bundle = new Bundle();
            bundle.putString(AppConst.WEBTYPE, AppConst.APP_VIP_WEB_PAY);
            bundle.putString(AppConst.WEBURL, vipInfoBean.getAppHomeVipUrl());
            openActivity(CommWebActivity.class, bundle);

        } else {
            if (vipInfoBean == null || vipInfoBean.getIntroduceInfo() == null) return;
            startActivity(VipDetailActivity.getLaunchIntent(getActivity(), vipInfoBean.getIntroduceInfo(), VipDetailActivity.TAG_ME));
        }
    }

    @Override
    public void loadVipInfoFail() {
        dismissProgressDialog();
    }

    @Override
    public void loadNewDocPreviewSuccess(String result) {

    }

    @Override
    public void getCustomVideoConfigureResutl(String result, String docId) {
        //  CustomVideoConfigure customVideoConfigure = new Gson().fromJson(result, CustomVideoConfigure.class);
        // AssetsDataUtils.setCustomVideoConfigure(customVideoConfigure);
        mPresenter.getCustomVideodoccontent(docId);
    }

    @Override
    public void getCustomVideodoccontentResult(String result) {
        Intent launchIntent = ChallengeZoneActivity.getLaunchIntent(getContext(), result);
        startActivity(launchIntent);
    }

    @Override
    public void getDocStringPreview(String result) {
        Bundle bundle = new Bundle();
        bundle.putString("module", result);
        bundle.putString(WorkPlatform.TYPE, WorkPlatform.W0RK);
        openActivity(MakeActivityV1_6.class, bundle);
    }

    private void setUiIsVip(boolean isVip, int integral) {
        if (isVip) {
            ivVipIcon.setBackgroundResource(R.mipmap.icon_mark_vip);
            itemData.get(3).setIntegral(integral);
            adapter.notifyDataSetChanged();
        } else {
            ivVipIcon.setBackgroundResource(R.mipmap.icon_mark_not_vip);
            itemData.get(3).setIntegral(integral);
            adapter.notifyDataSetChanged();
        }
    }

    @OnClick({R.id.id_ig_more, R.id.id_more_work, R.id.id_update_ry})
    public void onViewClicked(View view) {
        if (App.isLogin()) {
            if (userDetailInfoBean != null) {
                switch (view.getId()) {
                    case R.id.id_ig_more:
                    case R.id.id_update_ry:
                        Bundle bundle = new Bundle();
                        bundle.putString("userName", userDetailInfoBean.getUserInfo().getNickName());
                        bundle.putString("userSign", userDetailInfoBean.getUserInfo().getSign());
                        bundle.putString("AvatarUrl", userDetailInfoBean.getUserInfo().getAvatarUrl());
                        // bundle.putParcelable("userDetailInfoBean",userDetailInfoBean);
                        openActivity(UserinfoActivity.class, bundle);
                        break;
                    case R.id.id_more_work:
                        openActivity(MyWorksV3_0Activity.class);
                        break;
                    default:
                }
            } else {
                onResume();
            }

        } else {
            openActivity(LoginActivity.class);
        }

    }

    private void showCustomServiceWindow() {
        if (messageCenter == null) {
            messageCenter = new PopWindowMessageCenter(getActivity(), itemsOnClick);
            messageCenter.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    backgroundAlpha(1f);
                }
            });
        }
        backgroundAlpha(0.5f);
        messageCenter.showAtLocation(idRvMe, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        messageCenter.checkQQAndKey();

    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getActivity().getWindow().setAttributes(lp);
    }

    /****************
     * @param key 由官网生成的key
     * @return 返回true表示呼起手Q成功，返回fals表示呼起失败
     ******************/
    public boolean joinQQGroup(String key) {
        Intent intent = new Intent();
        intent.setData(Uri.parse(key));
//        intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26k%3D" + key));
        // 此Flag可根据具体产品需要自定义，如设置，则在加群界面按返回，返回手Q主界面，不设置，按返回会返回到呼起产品界面    //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        try {
            startActivity(intent);
            return true;
        } catch (Exception e) {
            // 未安装手Q或安装的版本不支持
            return false;
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    /**
     * 防止第一次启动无网络到有网络
     *
     * @param b
     */
    @Override
    public void onNetWorkStatusChange(boolean b) {
        if (b && isfirst) {
            onResume();
        }
    }

    @Override
    public void onNewWorkEnvironment(NetWorkObservable.NetStateChangeEvent.NetState netState) {

    }

    public class PcenterWorkAdapter extends ABaseRefreshAdapter<DocsBean> {

        public PcenterWorkAdapter(Context context, List<DocsBean> datas, int itemLayoutId) {
            super(context, datas, itemLayoutId);
        }

        @Override
        protected void convert(BaseRecyclerHolder baseRecyclerHolder, DocsBean docsBean, int postion) {
            RoundImageView iv_photo = baseRecyclerHolder.getView(R.id.id_ig_user_work);
            ViewGroup.LayoutParams layoutParams = iv_photo.getLayoutParams();
            //layoutParams.width = UIUtils.WH()[0] - UIUtils.px2dip(30) / 5;
            layoutParams.width = UIUtils.WH()[0] / 4 - UIUtils.dp2px(10);
            layoutParams.height = layoutParams.width;
            iv_photo.getImageView().setScaleType(ImageView.ScaleType.CENTER_CROP);
            ImageLoader.getInstance().showCircleImageWithBorderCenterCrop(getActivity(), docsBean.getThumb(), iv_photo.getImageView());
        }
    }

    public class PcenterAdapter extends ABaseRefreshAdapter<MineItemBean> {


        public PcenterAdapter(Context context, List<MineItemBean> datas, int itemLayoutId) {
            super(context, datas, itemLayoutId);
        }

        @Override
        protected void convert(BaseRecyclerHolder baseRecyclerHolder, MineItemBean s, int i) {
            TextView tv_name = baseRecyclerHolder.getView(R.id.tv_name);
            ImageView iv_photo = baseRecyclerHolder.getView(R.id.iv_photo);
            iv_photo.setImageResource(s.getRes());
            tv_name.setText(s.getItemName());
            TextView tv_integral = baseRecyclerHolder.getView(R.id.tv_integral);
            tv_integral.setText((s.getIntegral() / 100) + "");


            baseRecyclerHolder.getView(R.id.tv_integral).setVisibility(s.getIntegral() > -1 ? View.VISIBLE : View.GONE);
            baseRecyclerHolder.getView(R.id.tv_mine_vip_sign).setVisibility(s.isVip() ? View.VISIBLE : View.GONE);

        }
    }


}
